<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>移动动画的闭包使用</title>
    <style>
      button {
        position: absolute;
        margin: 20px;
      }
    </style>
  </head>
  <body>
    <button message="后盾人">houdunren</button>
    <button message="hdsms">hdcms</button>
  </body>
  <script>
    let btns = document.querySelectorAll("button");
    btns.forEach(function(item) {
      let interval = false;
      item.addEventListener("click", function() {
        if (!interval) {
          let left = 1;
          interval = true;
          setInterval(function() {
            item.style.left = left++ + "px";
          }, 100);
        }
      });
    });
  </script>
</html>
